package com.jlg.managers;


import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.jlg.beans.groupon.ApiTemplateBean;
import com.julewa.db.DB;
import com.julewa.db.Identifier;

/**
*
* author: huazhang
* since : 2011-3-15
*/
@Component
@SuppressWarnings("unchecked")
public class ApiTemplateManager
{
    private @Autowired
    DB db;
    private @Autowired
    Identifier idsrv;

    public boolean save(ApiTemplateBean om)
    {
        long id = idsrv.generate("apitemplate");
        om.setId(id);
        return db.insert("apitemplate.insert", om);
    }

    public Map<Long, ApiTemplateBean> getAll()
    {
        Map<Long, ApiTemplateBean> map = new HashMap<Long, ApiTemplateBean>();
        List<ApiTemplateBean> list = db.getList("apitemplate.all", null);
        if (list != null)
        {
            for (ApiTemplateBean om : list)
            {
                map.put(om.getId(), om);
            }
        }
        return map;
    }

}
